#-------------------------------------------
DEBUG_EN=1
APP=main
TOP_DIR=$(shell pwd)
ARCH=
CC=g++
CFLAGS= -Wall -Wfatal-errors -fpermissive 
#DLIBS= -lopencv_core -lopencv_imgproc -lopencv_highgui
DLIBS=
#CFLAGS= -Wall -Wfatal-errors -fpermissive `pkg-config --cflags --libs opencv`
#CFLAGS= -Wall  -fpermissive
LDFLAGS=
SRC_TOP=./src
OBJ_DIR=./obj/
##INC_DIRS=./inc
INC_DIRS=../Simulation/UE/UE_Tx_Front_FltC/common/head/  ../Simulation/UE/UE_Tx_Front_FltC/PRACH/  ../Simulation/UE/UE_Tx_Front_FltC/SRS/  ../Simulation/UE/UE_Tx_Front_FltC/PUSCH/head/  ../Simulation/UE/Front_FltC/  ../Simulation/CommLib_FltC/   ../Simulation/CommLib_FxpC/ ./    /usr/synopsys/vcs-mx/O-2018.09-SP2/include/
LIB_DIRS=


ifeq ($(DEBUG_EN), 1) 
CFLAGS+=-O0 -g -DDEBUG_EN -std=c++11
endif
# Dependencies if any
#LIBS= m openblas
LIBS= m 
DEPS=$(wildcard ../Simulation/UE/UE_Tx_Front_FltC/common/head/*.h  ../Simulation/UE/UE_Tx_Front_FltC/PRACH/*.h  ../Simulation/UE/UE_Tx_Front_FltC/SRS/*.h  ../Simulation/UE/UE_Tx_Front_FltC/PUSCH/head/*.h  ../Simulation/UE/Front_FltC/*.h  ../Simulation/CommLib_FltC/*.h  ../Simulation/CommLib_FxpC/*.h     ./*.h     /usr/synopsys/vcs-mx/O-2018.09-SP2/include/svdpi.h    )

CFLAGS+= $(foreach D,$(INC_DIRS),-I$D)
LDFLAGS+= $(foreach D,$(LIB_DIRS),-L$D) $(foreach L,$(LIBS), -l$(L))
##LDFLAGS+= 


#-------------------------------------------
# Source files for compilation
#-------------------------------------------

##SRCS=$(wildcard $(SRC_TOP)/*.cpp)
SRCS=$(wildcard ./*.cpp  ../Simulation/CommLib_FxpC/*.cpp ../Simulation/UE/Front_FxpC/*.cpp ../Simulation/UE/Front_FltC/*.cpp  ../Simulation/UE/UE_Tx_Front_FltC/PUSCH/source/*.cpp ../Simulation/UE/UE_Tx_Front_FltC/SRS/*.cpp ../Simulation/UE/UE_Tx_Front_FltC/PUCCH/*.cpp ../Simulation/UE/UE_Tx_Front_FltC/common/source/*.cpp  ../Simulation/CommLib_FltC/*.cpp  ../Simulation/UE/UE_Tx_Front_FltC/PRACH/*.cpp  )


SRCO=$(wildcard ./obj/*.o )


# List of all objects that are to be built
OBJS= $(addprefix $(OBJ_DIR), $(patsubst %.cpp, %.o, $(notdir $(SRCS))))

vpath %.cpp $(dir $(SRCS))



default:my_com gen_so
	

#-------------------------------------------
# Build targets
all : obj $(APP) $(DEPS)

$(APP): Makefile $(OBJ_DIR) $(OBJS)
	@echo "Linking..."
	$(CC)  -o $@  $(OBJS) $(LDFLAGS) $(DLIBS)

$(OBJ_DIR):
	mkdir -p $(OBJ_DIR)
	
$(OBJS):$(OBJ_DIR)%.o:%.cpp
	@echo "Building $@ from $<..."
	$(CC)  -pipe -fPIC -shared   -c $(CFLAGS) $< -o $@ $(DLIBS)
	
#-------------------------------------------

#-------------------------------------------
# Phony targets
#-------------------------------------------
.phony: clean clean_all

obj :
	mkdir -p obj

# Clean the common object files
clean:
	@echo "Removing all objects..."
	rm -rf $(OBJS)
	rm -f $(APP)
	rm -f *.so
	
# Clean all libraries if at all
ca: clean all 

# Print important variables and values
print:
	@echo "Compiler flags = $(CFLAGS)"
	@echo "Linker flags = $(LDFLAGS)"
	@echo "Source files = $(SRCS)"
	@echo "Object files = $(OBJS)"
	@echo "Dependencies = $(DEPS)"


my_run:
	g++  -Wall -Wfatal-errors -fpermissive  -O0 -g -DDEBUG_EN -std=c++11   $(SRCS)   $(foreach D,$(INC_DIRS),-I$D) $(foreach L,$(LIBS), -l$(L))    -o    my_test 

my_com:$(OBJS)
	##g++  -o  main   $(SRCO)  
	@echo "Compile done ..."	
	
gen_so:
	g++   -pipe -fPIC -shared -o main.so $(SRCO)



